package com.ikas.ai.server.module.morningpaper.model.elements;

import com.ikas.ai.server.module.morningpaper.consts.MorningPaperElementPriorities;
import com.ikas.ai.server.module.morningpaper.consts.MorningPaperNormalVariableNames;
import com.ikas.ai.server.module.morningpaper.exception.MorningPaperException;
import com.ikas.ai.server.module.morningpaper.model.dto.MorningPaperVariablesDto;
import com.ikas.ai.server.module.morningpaper.model.po.MorningPaperVariablesPo;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Lazy

public class ElementMachineWholePowerUpCount extends MorningPaperTopElement {

    protected String MORNING_PAPER_VARIABLE_NAME = MorningPaperNormalVariableNames.machineWholePowerUpCount.name();
    @Override
    public String getMorningPaperVariableName() {
        return MORNING_PAPER_VARIABLE_NAME;
    }
    protected MorningPaperElementPriorities PRIORITY = MorningPaperElementPriorities.THIRD_PRIORITY;
    @Override
    public MorningPaperElementPriorities getPriority(){
        return PRIORITY;
    }

    @Override
    public MorningPaperVariablesDto render(MorningPaperVariablesDto mv, Map<String, MorningPaperVariablesPo> variablesPoMap,Map<String,Object> transmitMap) {
        super.render(mv, variablesPoMap, transmitMap);
        try {
            Long count =mv.getMachineU01ConditionGPowerUpCount()
                    +mv.getMachineU01ConditionPPowerUpCount()
                    +mv.getMachineU01ConditionPCPowerUpCount()
                    +mv.getMachineU02ConditionGPowerUpCount()
                    +mv.getMachineU02ConditionPPowerUpCount()
                    +mv.getMachineU02ConditionPCPowerUpCount()
                    +mv.getMachineU03ConditionGPowerUpCount()
                    +mv.getMachineU03ConditionPPowerUpCount()
                    +mv.getMachineU03ConditionPCPowerUpCount()
                    +mv.getMachineU04ConditionGPowerUpCount()
                    +mv.getMachineU04ConditionPPowerUpCount()
                    +mv.getMachineU04ConditionPCPowerUpCount();
            mv.setMachineWholePowerUpCount(count);
            return mv;
        } catch (NullPointerException e) {
            throw new MorningPaperException(String.format(MorningPaperException.needsFieldIsEmpty,mv.toString()));
        }
    }

}
